@extends('admin.public.base')
<style>
    table th {
        min-width: 10px !important;
    }
</style>
@section('content')
    <div class="x-nav">
        <span class="layui-breadcrumb mbx_fl_10">
            <a href="">首页</a>
            <a href="">代理商管理</a>
            <a><cite>代理商列表</cite></a>
        </span>
        <a class="layui-btn layui-btn-small mbx_fr_10" style="line-height:1.6em;margin-top:3px"
           onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="name" placeholder="供应商名" autocomplete="off" value="{{ Request()->get('name') }}" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="mobile" placeholder="手机号" autocomplete="off" value="{{ Request()->get('mobile') }}" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" autocomplete="off" placeholder="开始日" name="start_time" id="start" value="{{request()->input('start_time')}}">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" autocomplete="off" placeholder="截止日" name="end_time" id="end" value="{{request()->input('end_time')}}">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                    <i class="layui-icon">&#xe615;</i>
                                </button>
                                <input type="hidden" id="export_excel" name="export_excel" value="0">
                                <button id="export_excel_btn" class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe65b;</i>导出Excel</button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-header">
                        <button class="layui-btn" onclick="xadmin.open('添加信息','/admin/store/storeAdd')">
                            <i class="layui-icon"></i>添加
                        </button>
                    </div>
                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-table layui-form">
                            <thead>
                            <tr>
                                <th>代理商编号</th>
                                <th>代理商</th>
                                <th>资质有效期</th>
                                <th>状态</th>
                                <th>申请时间</th>
                                <th>基础折扣率</th>
                                <th>货款余额</th>
                                <th>管理费余额</th>
                                <th>销售策略权限管理</th>
                                <th>商品权限管理</th>
                                <th>操作</th>
                                <th>充值操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach( $data as $item)
                                <tr>
                                    <td>{{ $item['store_sn'] }}</td>
                                    <td>{{ $item['store_name'] }}</td>
                                    <td>{{ $item['agent_end_time'] }}</td>
                                    <td>{{ $item['status'] }}</td>
                                    <td>{{ $item['apply_time'] }}</td>
                                    <td>{{ $item['discount_rate'] }}</td>
                                    <td>{{ $item['money_goods'] }}</td>
                                    <td>{{ $item['money_management'] }}</td>
                                    <td class="td-manage">
                                        <a  style="color: #1E9FFF" class="layui-btn layui-btn-primary layui-btn-sm"
                                            onclick="xadmin.open('金额满赠权限管理','/admin/store/salesStrategyViewPermissionsList?store_id={{ $item['id'] }}&type=1')"
                                            href="javascript:;">
                                            <i style="color: #1E9FFF" class="layui-icon">&#xe705;</i> 金额满赠
                                        </a>
                                        <br/>
                                        <a  style="color: #FFB800" class="layui-btn layui-btn-primary layui-btn-sm"
                                            onclick="xadmin.open('单品满赠权限管理','/admin/store/salesStrategyViewPermissionsList?store_id={{ $item['id'] }}&type=2')"
                                            href="javascript:;">
                                            <i style="color: #FFB800" class="layui-icon">&#xe705;</i> 单品满赠
                                        </a>
                                    </td>
                                    <td class="td-manage">
                                        <a  style="color: #1E9FFF" class="layui-btn layui-btn-primary layui-btn-sm"
                                           onclick="xadmin.open('商品权限管理','/admin/store/storeGoodsViewPermissionsList?store_id={{ $item['id'] }}')"
                                           href="javascript:;">
                                            <i style="color: #1E9FFF" class="layui-icon">&#xe705;</i> 商品权限
                                        </a>
                                    </td>
                                    <td class="td-manage">
                                        <a class="layui-btn layui-btn-xs layui-btn-sm" style="margin-top: 5px"
                                           onclick="xadmin.open('编辑','/admin/store/storeEdit?id={{ $item['id'] }}')"
                                           href="javascript:;">编辑</a>
                                        <a class="layui-btn layui-btn-xs layui-btn-sm" style="margin-top: 5px"
                                           onclick="xadmin.open('编辑','/admin/store/storePassword?id={{ $item['id'] }}',800,600)"
                                           href="javascript:;">修改密码</a>
                                        <a class="layui-btn layui-btn-normal layui-btn-sm" style="margin-top: 5px"
                                           onclick="xadmin.open('产品价格','/admin/store/storeGoodsEdit?id={{ $item['id'] }}')"
                                           href="javascript:;">产品价格</a>
                                    </td>
                                    <td class="td-manage">
                                        <a class="layui-btn layui-btn-warm layui-btn-sm" style="margin-top: 5px"
                                           onclick="xadmin.open('货款充值','/admin/store/storeRecharge?type=1&id={{ $item['id'] }}',800,600)"
                                           href="javascript:;">货款充值</a>
                                        <a class="layui-btn layui-btn-danger layui-btn-sm" style="margin-top: 5px"
                                           onclick="xadmin.open('管理费充值','/admin/store/storeRecharge?type=2&id={{ $item['id'] }}',800,600)"
                                           href="javascript:;">管理费充值</a>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            {{ $data->links('admin/public/page') }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use(['laydate', 'form'], function () {
            var laydate = layui.laydate;
            var form = layui.form;

            // 监听全选
            form.on('checkbox(checkall)', function (data) {
                if (data.elem.checked) {
                    $('tbody input').prop('checked', true);
                } else {
                    $('tbody input').prop('checked', false);
                }
                form.render('checkbox');
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#start', //指定元素
                type: 'datetime'
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end', //指定元素
                type: 'datetime'
            });
        });

        /*删除*/
        function confirm_del(obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                console.log(id);
                //发异步删除数据
                $.ajax({
                    type: 'POST',
                    url: '/admin/store/storeDel?id=' + id,
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function (data) {
                        if (data.code == 1) {
                            $(obj).parents("tr").remove();
                            layer.msg('已删除!', {icon: 1, time: 1000});
                        } else {
                            layer.alert(data.msg)
                        }
                    },
                    error: function (xhr, type) {
                        alert('Ajax error!')
                    }
                });
            });
        }

        $("#export_excel_btn").on('click', function() {
            layer.load(2, {
                time: 10000
            });
            $("#export_excel").val(1)
        });

        $("#search").on('click', function() {
            layer.load(2, {
                time: 10000
            });
            $("#export_excel").val(0);
        });
    </script>
@endsection